package com.doraemon.utils;

import com.alibaba.fastjson.JSON;
import com.doraemon.module.buyer.dto.OrderDTO;
import com.doraemon.module.buyer.entity.OrderDetail;
import com.doraemon.module.buyer.form.OrderForm;

import java.util.List;

/**
 * @author doraemon
 * @date 2017/12/19.
 */
public class OrderFrom2OrderDTOConverter {
    public static OrderDTO convert(OrderForm orderForm){
        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setBuyerOpenid(orderForm.getOpenid());
        orderDTO.setBuyerName(orderForm.getName());
        orderDTO.setBuyerPhone(orderForm.getPhone());
        orderDTO.setBuyerAddress(orderForm.getAddress());

        List<OrderDetail> orderDetails  = JSON.parseArray(orderForm.getItems(),OrderDetail.class);
        orderDTO.setOrderDetailList(orderDetails);
        return orderDTO;
    }

}
